package com.mvvm.start.base.base

import android.app.Dialog
import android.content.Context
import android.view.*
import androidx.databinding.ViewDataBinding
import com.mvvm.start.base.R
import com.mvvm.start.base.utils.getViewBinding


/**
 * @功能: Dialog的基类
 * @User Lmy
 * @Creat 2021/10/27 3:59 下午
 * @Compony 永远相信美好的事情即将发生
 */
abstract class BaseDialog<VB : ViewDataBinding>(
    val mContext: Context, themeResId: Int = R.style.DefaltDialog,
) : Dialog(mContext, themeResId) {
    val viewBinding: VB by lazy(mode = LazyThreadSafetyMode.NONE) {
        getViewBinding(layoutInflater, position = 0)
    }

    init {
        setContentView(viewBinding.root)
        initWindow(window!!)
        initView()
        initData()
        setCancelable(canCancel())
    }

    abstract fun initWindow(window: Window)
    abstract fun canCancel(): Boolean
    abstract fun initView()
    abstract fun initData()
    override fun dismiss() {
        viewBinding.unbind()
    }


}